<template>
    <div class="container" @click="toDetail(item.shareposts_id,'share')">
        <div class="userInfo">
            <img :src="item.avatar" alt="" class="avatar">
            <div class="nickname">{{item.nickname}}</div>
        </div>
        <div class="title">
            {{item.title}}
        </div>
        <div class="remark text-ellipsis">
            {{item.content}}
        </div>
        <div class="image-container">
            <div v-for="(image, index) in item.imgUrl" :key="index" class="images">
                <img :src="image" v-if="index < 3" alt="Image" class="image" />
            </div>
            <div v-show="item?.imgUrl?.length > 3" class="overlay">+{{ item?.imgUrl?.length - 3 }}</div>
        </div>
    </div>
    <van-divider :style="{ borderColor: 'rgb(153, 170, 188)', padding: '0 16px' }" />
</template>

<script setup lang='ts'>
import { useRouter } from 'vue-router';
const router = useRouter()
import {addhistory} from '@/api/index'
import { userStore } from '@/store';
const user = userStore();
const toDetail =async (id:string,type:string) => {
   await addhistory({id,browser_type:type,viewer_id:user.userInfo.user_id,browser_id:id})
    router.push({
      path: '/detailInfo',
      query: {
        id:id,
        type:type
      }
    })
  }

 defineProps({
    item: {
        type: Object,
        required: true,
    }
})

</script>

<style lang='less' scoped>
.container {
    display: grid;
    grid-template-rows: auto;
    align-items: center;
    width: 100%;
    padding: 0 15px;
    box-sizing: border-box;

    .userInfo {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        gap: 10px;
        position: relative;
        padding: 5px;

        .avatar {
            width: 30px;
            height: 30px;
            border-radius: 50%;
        }

        .btn {
            position: absolute;
            right: 60px;
            width: 60px;
            height: 30px;
            font-size: 13px;
        }

        .nickname {
            color: rgb(19, 20, 20);
            font-size: 18px;
            font-weight: 600;
        }
    }

    .title {
        font-weight: 800;
        font-size: 18px;
    }

    .remark {
        width: 100%;
        font-size: 1rem;
        font-weight: 500;
        line-height: 1.5;
        text-indent: 2em;
    }

    .images {
        display: flex;
        gap: 0.3125rem;
        flex-wrap: wrap;
        width: calc(33.33% - 10px);
        margin: 5px;
        object-fit: cover;

        img {
            aspect-ratio: 1;
            width: 100%;
            height: 6.25rem;
            border-radius: 0.3125rem;
        }
    }
}

.overlay {
    position: absolute;
  
  right: 0.3rem;
  top: 0.2rem;
  background-color: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  display: flex; /* 使用flex布局 */
  justify-content: center; /* 居中对齐 */
  align-items: center; /* 垂直居中对齐 */
  text-align: center;
  padding: 5px;
  height: 5.8rem;
  width: calc(33% - 18px);
}

.image-container {
    position: relative;
    display: flex;
    flex-wrap: wrap;
}

.text-ellipsis {
  display: -webkit-box;
  -webkit-line-clamp: 2; /* 限制为3行 */
  -webkit-box-orient: vertical; /* 设置为垂直方向 */
  overflow: hidden;
  text-overflow: ellipsis; /* 在文本超出时显示省略号 */
  line-height: 1.5; /* 根据需要设置行高 */
  box-sizing: border-box; /* 包括边框和内边距 */
}
</style>
